import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select
import os

# 打开游览器
driver = webdriver.Chrome()
driver.maximize_window()

# 请求本地网页
url = 'file:///' + os.path.dirname(os.path.abspath(__file__)) + '/html/注册实例.html'
driver.get(url)


# 切换到frame A注册表
a = driver.find_element(By.ID,'idframe1')  # 找到A表标签
driver.switch_to.frame(a)  # 切换到A表 frame


# 找到账号输入框并输入
driver.find_element(By.ID,'userA').send_keys('test6666')
# 找到密码输入框并输入
driver.find_element(By.ID,'passwordA').send_keys('test123456')
# 找到电话号码输入框并输入
driver.find_element(By.ID,'telA').send_keys('15624353254')
# 找到邮箱输入框并输入
driver.find_element(By.ID,'emailA').send_keys('15624353254@163.com')

# 找到下拉框选择需要的选项并点击
time.sleep(2)
s1 = driver.find_element(By.ID,'selectA')
s1.click()
select = Select(s1)  # 创建select对象使用
select.select_by_value('cq')  # 通过value选择值为cq的选项

# 弹出弹窗并确定
driver.find_element(By.ID,'alerta').click()
time.sleep(2)
alert = driver.switch_to.alert  # 切换到alert窗口
alert.accept()   # 弹窗确认

# 找到注册用户按钮并点击
driver.find_element(By.CSS_SELECTOR,'#zc > fieldset > button').click()

# 推出到主页面
driver.switch_to.default_content()


# 关闭游览器
time.sleep(2)
driver.quit()